package com.study.zzedu.fragment.notice;

import android.content.Context;
import android.text.TextUtils;

import com.study.zzedu.base.BaseModel;
import com.study.zzedu.http.OnResultListener;
import com.study.zzedu.utils.AppConstant;
import com.study.zzedu.utils.LogUtil;
import com.study.zzedu.utils.OkHttpUtils;

import org.json.JSONObject;

/**
 * Created by kiros on 2020/9/3.
 */

public class NoticeModel extends BaseModel {

    /*
  获取通知消息列表
  */
    public void getInfoList(Context context, final OnResultListener resultListener) {
        if (TextUtils.isEmpty(AppConstant.userCode)) {
            LogUtil.e("Forget", "学号异常");
            return;
        }
        OkHttpUtils.getInstance(context).getJsonForString(OkHttpUtils.BASE_URL + "/appNotice/getMyNotice", new String[]{"userCode","typeCode","pageNum","pageSize"},
                new String[]{AppConstant.userCode,"","0","15"}, new OkHttpUtils.HttpCallBack() {
            @Override
            public void onSuccess(String obj) {
                try {
                    JSONObject jObject = new JSONObject(obj);
                    if (0 == jObject.getInt("code")) {
                        resultListener.onSuccess(obj);
                    } else {
                        resultListener.onError(jObject.get("message").toString());
                    }
                } catch (Exception e) {
                    e.toString();
                }
            }
            @Override
            public void onSuccess(JSONObject obj) {
                //resultListener.onSuccess(obj.toString());
            }
            @Override
            public void onError(String msg) {
                resultListener.onError(msg);
            }
        });
    }

    public void getImgList(Context context, final OnResultListener resultListener) {
        OkHttpUtils.getInstance(context).getJsonForString(OkHttpUtils.BASE_URL + "/banner/queryBanner", null, null, new OkHttpUtils.HttpCallBack() {
            @Override
            public void onSuccess(String obj) {
                try {
                    JSONObject jObject = new JSONObject(obj);
                    if (0 == jObject.getInt("code")) {
                        resultListener.onSuccess(obj);
                    } else {
                        resultListener.onError(jObject.get("message").toString());
                    }
                } catch (Exception e) {
                    e.toString();
                }
            }

            @Override
            public void onSuccess(JSONObject obj) {
                //resultListener.onSuccess(obj.toString());
            }

            @Override
            public void onError(String msg) {
                resultListener.onError(msg);
            }
        });
    }



}
